package com.taotao.search.listener;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.springframework.beans.factory.annotation.Autowired;

import com.taotao.search.service.SearchService;

public class ItemChangeMessageListener implements MessageListener{

	//注入Service服务
	@Autowired
	private SearchService searchService;
	
	@Override
	public void onMessage(Message message) {
		// 判断消息是否为textMessage
		try {
			TextMessage textMessage = null;
			Long itemId = null;
			// 如果是获取商品id
			if(message instanceof TextMessage) {
				textMessage = (TextMessage)message;
				itemId = Long.parseLong(textMessage.getText());
			
			}
			// 通过商品的id查询商品，需要开发mappper来进行
			
			// 更新索引库
			searchService.updateSearchItemById(itemId);
		
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
